package siedler.communication;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;

public class Game implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	private int gameID;
	private Vector<PeerI> playerRefs = new Vector<PeerI>();
	private HashMap<Integer,String> playerIdAddressMap;
	

	protected Game(int id, Vector<PeerI> refs, HashMap<Integer,String> idAddressMap) throws RemoteException {
		this.gameID = id;
		
		for(int i = 0; i < refs.size(); i++){
			playerRefs.add(refs.elementAt(i));
		}
		
		System.out.println("N E W   G A M E !!");
		
		this.playerIdAddressMap = new HashMap<Integer,String>(idAddressMap);
		
		int key;
		Iterator iter = playerIdAddressMap.keySet().iterator();
		while(iter.hasNext()){
			key = (Integer)iter.next();
			System.out.println("GAME: id-add = "+ key+"-"+ idAddressMap.get(key));
		}
		
		
//		for(int i = 0; i < refs.size(); i++){
//			playerAdds.add(adds.elementAt(i));
//			System.out.println("Game "+id + " Peer added: " + i + " - " + playerAdds.elementAt(i) + "\n");
//		}
		
		//determineTokenHolder();
	}
	
//	public void determineTokenHolder() throws RemoteException{
//		tokenholder = playerRefs.get(0);
//		for(PeerI peer : playerRefs){
//			if(peer.getId() > tokenholder.getId()){
//				tokenholder = peer;
//			}
//		}
//	}
	
//	public void setTokenHolder(PeerI tokenholder) {
//		this.tokenholder = tokenholder;
//	}

	public Vector<PeerI> getPlayers(){
		return playerRefs;
	}
	
	public HashMap<Integer,String> getPlayerIdAddressMap(){
		return playerIdAddressMap;
	}

//	@Override
//	public PeerI getTokenHolder() throws RemoteException {
//		return tokenholder;
//	}
	
	

}
